<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Inicio extends CI_Controller {
	
	function __construct() {
		parent::__construct();
		
	}
	public function index(){
		$session_data = $this->session->userdata('protocolo');
		$data["session_data"] = $session_data;
		
	

		$this->load->view('header');
		$this->load->view('inicio');
	}
	
	
	public function relatorioatendimento(){
		//******************************************************
		//   PERMISSAO 
		//******************************************************
		$session_data = $this->session->userdata('grambel');
		temPermissao(array('1','2'),$session_data);
		
		if($this->input->post()){
		
			//------------------------------------------------------------------------------------------------------------------------
		
			$pdf = new Pdf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
			gerarRelatorio($pdf);
			$pdf->AddPage('L', 'A4');
			
			// TITULO DA PAGINA
			$pdf->Write(0, 'CONTROLE DE TELEFONEMAS', '', 0, 'C', true, 0, false, false, 0);
			$pdf->Ln();
			// TITULO DA PAGINA
			$pdf->Write(0, 'Periodo: '.$this->input->post('inicio').' a '.$this->input->post('fim'), '', 0, 'C', true, 0, false, false, 0);
			$pdf->Ln();
			
			$ate = new Atendimento();
			$ate = $ate->relatorioAtendimento($this->input->post('tipoligacao'),brToUsa($this->input->post('inicio')),brToUsa($this->input->post('fim')));
			

			//*************************************************************************************
			// CABEÇALHO
			//*************************************************************************************
			$header = array('Data','Ramal','Solicitante','Telefone','Solicitado','Assunto','DDD','Responsavel');
			// Colors, line width and bold font
			$pdf->SetFillColor(208, 208, 208);
			$pdf->SetTextColor(0);
			$pdf->SetDrawColor(0, 0, 0);
			$pdf->SetLineWidth(0.3);
			$pdf->SetFont('times', 'B', 7);
			
			// Header
			$w = array(23, 20, 40,20, 40, 50,15, 50);
			$num_headers = count($header);
			for($i = 0; $i < $num_headers; ++$i) {
				$pdf->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
			}
			$pdf->Ln();
			//*************************************************************************************
			// DADOS
			//*************************************************************************************
			// Color and font restoration
			$pdf->SetFillColor(224, 235, 255);
			$pdf->SetTextColor(0);
			$pdf->SetFont('times', '', 7);
			// Data
			$fill = 0;

			foreach($ate as $r){	
			
				$pdf->Cell($w[0], 6,$r->dt_cadastro, 'LR', 0, 'L', $fill);
				$pdf->Cell($w[1], 6,$r->ramal, 'LR', 0, 'L', $fill);
				$pdf->Cell($w[2], 6,$r->solicitante, 'LR', 0, 'L', $fill);
				$pdf->Cell($w[3], 6,$r->telefone, 'LR', 0, 'L', $fill);
				$pdf->Cell($w[4], 6,$r->solicitado, 'LR', 0, 'L', $fill);
				$pdf->Cell($w[5], 6,$r->assunto, 'LR', 0, 'L', $fill);
				$pdf->Cell($w[6], 6,$r->tipoligacao, 'LR', 0, 'L', $fill);
				$pdf->Cell($w[7], 6,$r->nome_completo, 'LR', 0, 'L', $fill);
				$pdf->Ln();
				$fill=!$fill;
				
			}
			// FINALIZA TABELA
				$pdf->Cell(array_sum($w), 0, '', 'T');
			
				
		
		/*
		$html = "";
		$pdf->writeHTML($html, true, false, true, false, '');
		*/
		
		$pdf->Output('Relatorio_Devolucao.pdf', 'I');
			
			
		}else{
				
			
			/*$secretaria = new Secretaria();
			$data["secretaria"] = $secretaria->consultaSecretaria();*/
			
			$this->load->view('header');
			$this->load->view('view_atendimento_relatorio');
		}
	}
	
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */